import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

interface IAction {
  List<String> getTriggers();
  List<String> getSubjects();

  ActionItem findActionBy(String trigger);
}

class ActionItem {
  private List<String> triggers;
  private List<String> subjects;
  private List<String> consumed;
  private List<String> produced;
  private String narration;

  public List<String> getTriggers() {
    return triggers;
  }

  public void setTriggers(List<String> triggers) {
    this.triggers = triggers;
  }

  public List<String> getSubjects() {
    return subjects;
  }

  public void setSubjects(List<String> subjects) {
    this.subjects = subjects;
  }

  public String getNarration() {
    return narration;
  }

  public void setNarration(String narration) {
    this.narration = narration;
  }

  public List<String> getConsumed() {
    return consumed;
  }

  public void setConsumed(List<String> consumed) {
    this.consumed = consumed;
  }

  public List<String> getProduced() {
    return produced;
  }

  public void setProduced(List<String> produced) {
    this.produced = produced;
  }
}

class Action implements IAction {
  Action() {
    actions = new ArrayList<>();
  }

  private List<ActionItem> actions;

  public void setActions(List<ActionItem> actions) {
    this.actions = actions;
  }

  public List<ActionItem> getActions() {
    return actions;
  }

  @Override
  public List<String> getTriggers() {
    return actions.stream().map(ActionItem::getTriggers).flatMap(Collection::stream).toList();
  }

  @Override
  public List<String> getSubjects() {
    return actions.stream().map(ActionItem::getSubjects).flatMap(Collection::stream).toList();
  }

  @Override
  public ActionItem findActionBy(String trigger) {
    return actions.stream().filter(actionItem -> actionItem.getTriggers().contains(trigger)).findFirst().orElse(null);
  }

}
